package com.Springdemo.controller;

import com.Springdemo.enity.User;
import com.Springdemo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author: lool
 * @Date: 2022-06-10 20:08
 * @Description:    1.修改个人用户信息
 */


@Controller
@RequestMapping("user")
public class UserController {
    @Autowired
    private UserService userService;

    @PutMapping("/save")
    @ResponseBody             //修改个人信息
    public int saveUser(@RequestBody User user,HttpServletResponse response){
        System.out.println("save User--------------------------");
        userService.update(user);
        System.out.println(user.getPassword());
        return 200;
    }

    @RequestMapping("list")
    @ResponseBody  //返回的对象交给jackson-databind进行转json并输出的操作
    public List<User> list(HttpServletResponse response){
        System.out.println("UserController.list");
        User user = new User();
        user.setUsername("ANDY");
        user.setPassword("eyrt");
        User user2 = new User();
        user2.setUsername("hang");
        user2.setPassword("asd");
        List<User> userList = new ArrayList<>();
        userList.add(user);
        userList.add(user2);
        return userList;
    }
}

